package www.rlicker.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import www.rlicker.dao.IAgentDao;
import www.rlicker.dao.IProductDao;
import www.rlicker.model.Agent;
import www.rlicker.mybatis.Criteria;
import www.rlicker.service.IAgentService;
import www.rlicker.utils.MessageConstant;
import www.rlicker.utils.TranslateToMap;


@Service
public class AgentServiceImpl implements IAgentService{


	public List<Map<String, Object>>  queryPage (Criteria<Agent> param){
		List<Agent> list = agentRepository.queryPage(param);
		List<Map<String,Object>> map = TranslateToMap.convertListBean2ListMap(list,Agent.class);
	return map;  }

	public Integer queryPageCount (Criteria<Agent> param){
		return (Integer) agentRepository.queryPageCount(param);
	}

	public Agent  queryEntity (Long id){
		return agentRepository.queryEntity(id);
	}

	public String deleteById (Long id ){
		int result = agentRepository.deleteById(id);
			if ( result != 1) {
					return MessageConstant.USER_TYPE_3;
			}
			return null;
	}

	public String insert(Agent record ){
		int result = agentRepository.insert(record);
			if ( result != 1) { 
					return MessageConstant.USER_TYPE_4;
			}
			return null;
	}

	public String update (Criteria<Agent> param){
		int result = agentRepository.update(param);
			if ( result != 1) { 
					return MessageConstant.USER_TYPE_5;
			}
			return null;
	}
	
	@Override
	public List<Map<String, Object>> queryPageList(Criteria<Agent> param) {
		List<Agent> list = agentRepository.queryPageList(param);
	/*	list.forEach(f -> {
			
		});*/
		List<Map<String,Object>> map = TranslateToMap.convertListBean2ListMap(list,Agent.class);
	return map;  }

	@Override
	public Integer queryPageListCount(Criteria<Agent> param) {
		return (Integer) agentRepository.queryPageListCount(param);
	}

	@Resource
	private IAgentDao agentRepository;
	
	@Resource
	private IProductDao productepository;

}